<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    


    <script>
        // 将每个对象的price和count相乘，
        // 得到单个对象的total，
        // 最终累加
        var arr = [
            {price: 10, count: 1},
            {price: 11, count: 2},
            {price: 12, count: 3},
            {price: 13, count: 4},
            {price: 14, count: 5},
            {price: 15, count: 6},
            {price: 16, count: 7}
        ]

        let total = 0

        // for (let i = 0; i < arr.length; i++) {
        //     total += arr[i]
        // }

        // arr.forEach(item => {
        //     total += item
        // })

        total = arr.reduce(function (prev, next) {
            console.log('prev', prev) // 0
            console.log('next', next) // {price: 10, count: 1}
            // 10

            // console.log('prev', prev) // 10
            // console.log('next', next) // {price: 11, count: 2}
            // 10+11*2
            // 32.price * 32.count
            return prev + (next.price * next.count)
        }, 0)

        console.log(total)
    </script>
</body>
</html>